//
//  PersonalCenterViewController.m
//  QingBrushTopic
//
//  Created by Zheng on 2017/10/8.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "PersonalCenterViewController.h"

#import "PersonalCenterCell.h"
#import "PersonalCenterHeaderView.h"

@interface PersonalCenterViewController ()

@property (nonatomic, strong) PersonalCenterHeaderView *headerView;

@property (nonatomic, strong) NSArray<NSString *> *titlesArr;

@end

@implementation PersonalCenterViewController



#pragma mark - 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    

    self.myTableView.tableHeaderView = self.headerView;
    
    [self.myTableView registerClass:[PersonalCenterCell class] forCellReuseIdentifier:kPersonalCenterCell_ID];
    
    //监听头视图点击事件
    [self headerViewClickAction];
}

#pragma mark - 用户点击事件
- (void)headerViewClickAction {
//    kDefineWeakSelf
    _headerView.clickAction = ^{
        NSLog(@"个人信息");
    };
}

- (void)selectRowActionWithSection:(NSInteger)section {
    switch (section) {
        case 0:
        {
            //TODO:我的消息
            NSLog(@"我的消息");
        }
            break;
        case 1:
        {
            //TODO:我的成绩
            NSLog(@"我的成绩");
        }
            break;
        case 2:
        {
            //TODO:设置
            NSLog(@"设置");
        }
            break;
        default:
            break;
    }
}

#pragma mark - lazy load
- (PersonalCenterHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[PersonalCenterHeaderView alloc] init];
        _headerView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, kCX_Scale(150));
        _headerView.backgroundColor = [UIColor whiteColor];
        _headerView.nicknameLbl.text = @"用户昵称";
        _headerView.userIdLbl.text = @"用户id";
    }
    return _headerView;
}

- (NSArray<NSString *> *)titlesArr {
    if (!_titlesArr) {
        _titlesArr = @[@"我的消息",@"我的成绩",@"设置"];
    }
    return _titlesArr;
}


#pragma mark - tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PersonalCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:kPersonalCenterCell_ID forIndexPath:indexPath];
    
    cell.iconImgv.image = [UIImage imageNamed:[NSString stringWithFormat:@"pc_icon_%ld",(long)indexPath.section]];
    cell.titleLbl.text = self.titlesArr[indexPath.section];
    cell.markImgv.image = kIMAGE(@"pc_mark");
    
    return cell;
}


#pragma mark - tableview delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kCX_Scale(55);
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self selectRowActionWithSection:indexPath.section];
}

#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
